package com.climber.android.commonsdk.util

import android.text.TextPaint
import android.text.style.ClickableSpan
import android.view.View
import com.climber.android.commonsdk.R
import com.climber.android.commonsdk.app.AppConstants
import com.climber.android.commonsdk.arouter.ARouterPathConstants
import com.climber.android.commonsdk.helper.BundleHelper
import io.ganguo.library.mvp.arouter.ARouterUtils

/**
 * Created by Mikes at 2019-07-12 15:24
 */
class WebLinkClickSpan(private val linkUrl : String, private val preferTitle : String?=null) : ClickableSpan(){
    override fun onClick(widget: View) {
        ARouterUtils.navigation(ARouterPathConstants.PATH_WEB_BROWSER,
                ARouterUtils.INVALID_FLAG,
                BundleHelper()
                    .putString(AppConstants.PARAM_WEB_URL, linkUrl)
                    .putString(AppConstants.PARAM_WEB_TITLE, preferTitle ?: "")
                    .build(),
                R.anim.cbase__slide_in_from_right, R.anim.cbase__slide_out_to_left)
    }

    override fun updateDrawState(ds: TextPaint) {
        super.updateDrawState(ds)
        ds.isUnderlineText = false
    }
}

abstract class NoUnderLineClickSpan : ClickableSpan(){
    override fun updateDrawState(ds: TextPaint) {
        super.updateDrawState(ds)
        ds.isUnderlineText = false
    }
}